<?php
/**
 * @annotate 企业设置类
 * @group   Admin/Company
 * @author   yachtxiao <fuck@fackyou.org>
 */
class ResumeAction extends BaseAction {
	protected $aVerify = array(
		   	'resume_list',
		   	'yuyue',
		   	'del_send_resume',
		   	'edit_check',
		   	'wei_send_resume',
		   	'yuyue_list',
		  	);//需要验证的方法
	public function resume_list(){
		$this->assign("Title","应聘者管理");
		$cid = $_SESSION['company']['cid'];
		$com_info = D('company_info')->where(array('cid'=>$cid,'is_del'=>0))->find();
		$this->assign('manage',$com_info['contact']);
		$this->assign('address',$com_info['address']);
		if($com_info['phone'] == ""){
			$this->assign('phone',$com_info['call']);
		}else{
			$this->assign('phone',$com_info['phone']);
		}
		$hiid = D('hiring')->where(array('cid'=>$cid))->getField('hiring_id',true);
		$hiring_id = $_GET['hiring_id'];
		if(!empty($hiring_id)){
			$map['hiring_id'] = $hiring_id;
		}else{
			$map['hiring_id'] = array('in',$hiid);
		}
		$map['is_del'] = 0;
		//今天投递简历数
		$timetoday = strtotime(date("Y-m-d",time()));
		$m['hiring_id'] = array('in',$hiid);
		$m['send_time'] = array('egt',$timetoday);
		$m['is_del'] = 0;
		$cou = D('send_resume')->where($m)->count();
		$this->assign('cou',$cou);
		import('ORG.Util.Page');//导入分页类
		$count =D('send_resume')->where($map)->order('send_time desc')->count();
		$Page = new Page($count,20);
        $show = $Page ->show();
		$map['is_check'] = array('neq',2);
        $list = D('send_resume')->where($map)->order('send_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$job = D('hiring')->getField('hiring_id,title');
		foreach($list as $k=>$v){
			$list[$k]['resume'] =  D('resume')->where(array('resume_id'=>$v['resume_id']))->find();
			$list[$k]['info'] =  D('member_info')->where(array('uid'=>$list[$k]['resume']['uid']))->find();
			$list[$k]['info']['face'] = get_img_url($list[$k]['info']['face']);
			$list[$k]['exper'] =  D('exper')->where(array('uid'=>$list[$k]['resume']['uid'],'is_del'=>0))->select();
			$list[$k]['jobname'] = $job[$list[$k]['hiring_id']];
		}
		$this->assign('page',$show);
		$this->assign('list',$list);
		$menu = D('Company_menu')->select_menu();
		$this->assign('interview',$menu['interview']);
		$this->display();
	}
	
	//预约面试
	public function yuyue(){
		$this->checkPost();
		$id = getRequest('id');
		$map['is_check'] = 2;
		$map['mtime'] = getRequest('mh_date');
		$map['time'] = getRequest('time');
		$map['address'] = getRequest('address');
		$map['manage'] = getRequest('manage');
		$map['phone'] = getRequest('phone');
		$da = D('send_resume')->where(array('id'=>$id))->save($map);
		if($da){
			$send_info = D('send_resume')->where('id = '.$id)->find();
			$hiring_info = D('hiring')
								->join(C('DB_PREFIX').'company ON '.C('DB_PREFIX').'company.cid = '.C('DB_PREFIX').'hiring.cid')
								->join(C('DB_PREFIX').'company_info ON '.C('DB_PREFIX').'company_info.cid = '.C('DB_PREFIX').'hiring.cid')
								->where(C('DB_PREFIX').'hiring.hiring_id = '.$send_info['hiring_id'])
								->find();
			$resume_info = D('resume')
								->join(C('DB_PREFIX').'member_info ON '.C('DB_PREFIX').'resume.uid = '.C('DB_PREFIX').'member_info.uid')
								->join(C('DB_PREFIX').'member ON '.C('DB_PREFIX').'resume.uid = '.C('DB_PREFIX').'member.uid')
								->where(C('DB_PREFIX').'resume.resume_id = '.$send_info['resume_id'])
								->find();
			$data = array(
						'first' => array('value'=>$resume_info['truename']."，你好！\n你收到公司面试通知啦！",'color'=>'#000'),
						'job' => array('value'=>$hiring_info['title'],'color'=>'#000'),
						'company' => array('value'=>$hiring_info['company_name'],'color'=>'#000'),
						'time' => array('value'=>$send_info['mtime'].' '.$send_info['time'],'color'=>'#000'),
						'address' => array('value'=>$hiring_info['address'],'color'=>'#000'),
						'remark' => array('value'=>'记得准时参加哦~','color'=>'#000')
					);
			$wxbinds = D('hiring_info')->where('hiring_id = '.$send_info['hiring_id'])->find();
			$notices = D('company_manage')->where('bid IN('.$wxbinds['notice'].')')->select();
			foreach($notices as $k => $v){
				$data['contact'] = array('value'=>$v['wx_name'],'color'=>'#000');
				$data['tel'] = array('value'=>$v['wx_phone'],'color'=>'#000');
			}
			if($resume_info['wx_id']!=''){
				weixinmessage('mianshi',$data,$resume_info['wx_id'],'',1);
			}
			if($resume_info['wx_id2']!=''){
				weixinmessage('mianshi',$data,$resume_info['wx_id2'],'',2);
			}
			if($resume_info['wx_id3']!=''){
				weixinmessage('mianshi',$data,$resume_info['wx_id3'],'',3);
			}
			$this->success('预约成功!');
		}
	}
	
	public function del_send_resume(){
		$da['id'] = getRequest('id');
		$map['is_del'] = 1;
		$ba = D('send_resume')->where($da)->save($map);
		if($ba){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	public function edit_check(){
		$da['id'] = getRequest('id');
		$ba = D('send_resume')->where($da)->find();
		if($ba['is_check']==0){
			$map['is_check'] = 1;
			$dd = D('send_resume')->where($da)->save($map);
		
			if($ba){
				$this->ajaxReturn('','success',1);
			}else{
				$this->ajaxReturn('','error',0);
			}
		}else{
			$this->ajaxReturn('eee','success',1);
		}
	}
	public function wei_send_resume(){
		$da['id'] = getRequest('id');
		$map['is_audition'] = getRequest('is');
		$ba = D('send_resume')->where($da)->save($map);
		if($ba){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	public function yuyue_list(){
		$this->assign("Title","预约管理");
		$cid = $_SESSION['company']['cid'];
		$hiid = D('hiring')->where(array('cid'=>$cid))->getField('hiring_id',true);
		$m['hiring_id'] = array('in',$hiid);
		$m['is_check'] = 2;
		//今天投递简历数
		$m['mtime'] = array('neq',"");
		$m['is_del'] = 0;
		import('ORG.Util.Page');//导入分页类
		$count =D('send_resume')->where($m)->order('send_time desc')->count();
		$Page = new Page($count,20);
        $show = $Page ->show();
        $list = D('send_resume')->where($m)->order('send_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$job = D('hiring')->getField('hiring_id,title');
		foreach($list as $k=>$v){
			$list[$k]['resume'] =  D('resume')->where(array('resume_id'=>$v['resume_id']))->find();
			$list[$k]['info'] =  D('member_info')->where(array('uid'=>$list[$k]['resume']['uid']))->find();
			$list[$k]['info']['face'] = get_img_url($list[$k]['info']['face']);
			$list[$k]['exper'] =  D('exper')->where(array('uid'=>$list[$k]['resume']['uid'],'is_del'=>0))->select();
			$list[$k]['jobname'] = $job[$list[$k]['hiring_id']];
		}
	
		$this->assign('page',$show);
		$this->assign('list',$list);
		$this->display();
	}
	public function del_resume_list(){
		$this->assign("Title","已删除简历");
		$cid = $_SESSION['company']['cid'];
		$hiid = D('hiring')->where(array('cid'=>$cid))->getField('hiring_id',true);
		$m['hiring_id'] = array('in',$hiid);
		$m['is_del'] = 1;
		import('ORG.Util.Page');//导入分页类
		$count =D('send_resume')->where($m)->order('send_time desc')->count();
		$Page = new Page($count,20);
        $show = $Page ->show();
        $list = D('send_resume')->where($m)->order('send_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$job = D('jobs')->getField('jobs_id,title');
		foreach($list as $k=>$v){
			$list[$k]['resume'] =  D('resume')->where(array('resume_id'=>$v['resume_id']))->find();
			$list[$k]['info'] =  D('member_info')->where(array('uid'=>$list[$k]['resume']['uid']))->find();
			$list[$k]['info']['face'] = get_img_url($list[$k]['info']['face']);
			$list[$k]['exper'] =  D('exper')->where(array('uid'=>$list[$k]['resume']['uid'],'is_del'=>0))->select();
			$list[$k]['jobname'] = $job[$list[$k]['jobs_id']];
		}
	
		$this->assign('page',$show);
		$this->assign('list',$list);
		$this->display();
	}
	public function getvoiceurl(){
		$mp3url = getvoice($_GET['voice']);
		header('Content-type: audio/mp3');  
		header('Content-Disposition: attachment; filename="'.rand(1000000,9999999).'.mp3"');  
		readfile($mp3url);  
	}
}
?>